/**
 * @desc 格式化日期字符串
 * @param { String } - [date] 日期字符串(2020-01-14 13:43:23)
 * @param { String } - [formatStr] 日期格式
 */
export function formatDate(params) {
    let defalutParams = {
      date: new Date(new Date().getTime()),
      formatStr: 'yyyy-MM-dd HH:mm:ss'
    };
    params = { ...defalutParams, ...params };
  
    let date = new Date(new Date(params.date).getTime());
    let formatStr = params.formatStr;
  
    formatStr = formatStr.replace(new RegExp('yyyy'), `${date.getFullYear()}`);
    const month = date.getMonth() + 1;
    formatStr = formatStr.replace(new RegExp('MM'), `${month > 9 ? month : '0' + month}`);
    const day = date.getDate();
    formatStr = formatStr.replace(new RegExp('dd'), `${day > 9 ? day : '0' + day}`);
    const hour = date.getHours();
    formatStr = formatStr.replace(new RegExp('HH'), `${hour > 9 ? hour : '0' + hour}`);
    const min = date.getMinutes();
    formatStr = formatStr.replace(new RegExp('mm'), `${min > 9 ? min : '0' + min}`);
    const sec = date.getSeconds();
    formatStr = formatStr.replace(new RegExp('ss'), `${sec > 9 ? sec : '0' + sec}`);
  
    return formatStr;
  }
  